/*
 * Lexer.h
 *
 *  Created on: 30 Apr 2010
 *      Author: Guobc
 */

#ifndef LEXER_H_
#define LEXER_H_
#pragma warning(disable:4290)
#include <fstream>
#include <string>
#include "Token.h"
#include "ParserException.h"
#include "TokenType.h"
#include "ASTDom.h"

using namespace std;

namespace HA {
class ASTDom;

class Lexer {

public:

	/**
	 * Construct method.
	 */
	Lexer() :
		fin(), fName(""), mDocument(NULL) {

	}
	/**
	 * construct method
	 * @param name HTML file name
	 * */
	Lexer(string name) :
		fin(), fName(name), mDocument(NULL) {
	//	fin.open(name.c_str());
	}


	/**
	 * Set document to lexer
	 * @param document.
	 */
	virtual void setDocument(ASTDom* document) = 0;

	/**
	 * Get document of this lexer.
	 * @return
	 */
	virtual ASTDom* getDocument() = 0;

	/**
	 * Open this lexer input stream.
	 * @return True if success, false otherwise.
	 */
	virtual bool open() = 0;

	/**
	 * Test whether input stream is open.
	 * @return True is open, false otherwise.
	 */
	virtual bool isOpen() = 0;

	/**
	 * close this lexer input stream.
	 * @return True if success, false otherwise.
	 */
	virtual void close() = 0;

	/**
	 * Get the position from the input character stream.
	 * @return
	 */
	virtual int getPosition() = 0;

	/**
	 * Get the line number from the input character stream.
	 * return
	 */
	virtual int getLineNumber() = 0;

	/*
	 * Return next token.
	 *
	 * @return A token.
	 * */
	virtual Token* nextToken() throw (ParserException) = 0;

protected:

	/**
	 * Fetch a token from the input character stream.
	 * @return A token.
	 */
	virtual Token* fetchToken() throw (ParserException) = 0;

protected:
	ifstream fin;
	string fName;
	ASTDom* mDocument;

};
}

#endif /* LEXER_H_ */
